from datetime import datetime
import random


money = 50000
l = []
s = 0
c = 0
thing = ['水', '薯片', '糖果', '可乐', '纸巾', '杯子', '牙刷']
price = [2, 10, 6, 8, 20, 100, 30]
discount = ['谢谢惠顾', '水的5折优惠', '薯片的6折优惠', '糖果的7折优惠', '可乐的8折优惠', '纸巾的9折优惠', '杯子的4折优惠', '牙刷的3折优惠', '谢谢惠顾', '谢谢惠顾']

while money != 0 and thing != 0:
    r = random.choice(discount)
    a = input("请输入商品：")
    if a in thing:
        print("有这个商品")
        b = thing.index(a)
        if r == '谢谢惠顾' and b == 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 or 0:
            c += price[b]
            print("很遗憾，您没有抽到优惠券！")
        elif r == '水的5折优惠' and b == 1:
            c += price[b] * 0.5
            print("恭喜您抽到了水的5折优惠券")
        elif r == '薯片的6折优惠' and b == 2:
            c += price[b] * 0.6
            print("恭喜您抽到了薯片的6折优惠券")
        elif r == '糖果的7折优惠' and b == 3:
            c += price[b] * 0.7
            print("恭喜您抽到了糖果的7折优惠券")
        elif r == '可乐的8折优惠' and b == 4:
            c += price[b] * 0.8
            print("恭喜您抽到了可乐的8折优惠券")
        elif r == '纸巾的9折优惠' and b == 5:
            c += price[b] * 0.9
            print("恭喜您抽到了纸巾的9折优惠券")
        elif r == '杯子的4折优惠' and b == 6:
            c += price[b] * 0.4
            print("恭喜您抽到了杯子的4折优惠券")
        elif r == '牙刷的3折优惠' and b == 7:
            c += price[b] * 0.3
            print("恭喜您抽到了牙刷的3折优惠券")
        e = c
        if money >= e:
            time = datetime.now()
            s += 1
            l.append(a)
            q = input("是否退货：")
            if q == '否':
                print("请继续。")
            elif q == '是':
                p = input("请选择退货商品：")
                l.remove(p)
                print("已将商品退回！")
            t = input("是否继续购物：")
            if t == '是':
                money -= e
                continue
            elif t == '否':
                money -= e
                input("请输入q或Q退出：")
                print(f"购物时间：{str(time)}，恭喜，购买成功！您的卡余额还剩：{money}，您购买了：{s}件商品，购买总商品的价值是：{c}")
                break
        elif money < e:
            print("穷鬼，钱不够！请到其他超市购买！")
    else:
        print("没有这个商品，别瞎搞！")
    input("请输入q或Q退出：")
    print('您什么都没有买，卡余额还剩：%d' % money)
    break
else:
    print("无法购物")
